﻿var timers = require("sdk/timers");
var setTimeout = timers.setTimeout;
var clearTimeout = timers.clearTimeout;
var setInterval = timers.setInterval;
var clearInterval = timers.clearInterval;

var logs = [];

function init()
{
    setInterval(show, 250);
}
exports.init = init;

function log(val)
{
    logs.push({type : 'log', val : val});
}
exports.log = log;

function info(val)
{
    logs.push({ type: 'info', val: val });
}
exports.info = info;

function debug(val)
{
    logs.push({ type: 'debug', val: val });
}
exports.debug = debug;

function warn(val)
{
    logs.push({ type: 'warn', val: val });
}
exports.warn = warn;

function error(val)
{
    logs.push({ type: 'error', val: val });
}
exports.error = error;

function show()
{
    var str = '';
    if (logs.length === 0)
        return;
    for(var o of logs)
    {
        var type = o.type;
        var val = o.val;
        str += "\n<" + type + "> : " + val;
    }
    logs = [];
    console.log(str);
}